//
//  WPFirstCellView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/26.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPSecondViewOfBtnView.h"

@interface WPSecondViewOfBtnView ()

@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *introduceLabel;
@property(nonatomic,strong)UIButton *coverBtn;
@property(nonatomic,copy)void(^clickBlock)();

@end

@implementation WPSecondViewOfBtnView

-(instancetype)initWith:(NSString *)imageName title:(NSString *)title introduceStr:(NSString *)introduceStr clickBlock:(void(^)())clickBlock
{
        if (self = [super init]) {
            
            self.clickBlock = clickBlock;
           
            self.iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
            [self.iconView sizeToFit];
            [self addSubview:self.iconView];
            
            self.titleLabel = [[UILabel alloc] init];
            self.titleLabel.font = [UIFont systemFontOfSize:16];
            self.titleLabel.text = title;
            self.titleLabel.textAlignment = NSTextAlignmentCenter;
            [self.titleLabel sizeToFit];
            [self addSubview:self.titleLabel];
            
            self.introduceLabel = [[UILabel alloc] init];
            self.introduceLabel.font = [UIFont systemFontOfSize:12];
            self.introduceLabel.textColor = RGB_COLOR(160, 160,160);
            self.introduceLabel.text = introduceStr;
            self.introduceLabel.numberOfLines = 0;
//            self.introduceLabel.textAlignment = NSTextAlignmentLeft;
            [self.introduceLabel sizeToFit];
            [self addSubview:self.introduceLabel];
            
            self.coverBtn = [[UIButton alloc] init];
            [self.coverBtn addTarget:self action:@selector(coverBtnDidClick:) forControlEvents:UIControlEventTouchDown];
            [self addSubview:self.coverBtn];
            
            [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self).offset(10);
                make.centerY.equalTo(self);
                make.width.height.mas_equalTo(50);
                
            }];
            
            [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.iconView.mas_right).offset(10);
                make.top.equalTo(self.iconView);
            }];
            
            [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleLabel.mas_bottom).offset(13);
                make.left.equalTo(self.titleLabel.mas_left);
                make.right.equalTo(self);
            }];
            
            [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(self);
            }];
        }
        return self;
}

-(void)coverBtnDidClick:(UIButton *)btn
{
    if (self.clickBlock) {
        self.clickBlock();
    }
}

@end
